package com.briup.oagg.facade.web.controller.dataset;

import com.briup.oagg.facade.web.vm.page.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.facade.service.dateset.ITrapService;
import com.briup.oagg.facade.web.vm.dataset.TrapAddVM;
import com.briup.oagg.facade.web.vm.dataset.TrapTypeVM;
import com.briup.oagg.facade.web.vm.dataset.TrapUpdateVM;
import com.briup.oagg.facade.web.vm.dataset.TrapVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 圈闭信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "1.3.圈闭管理服务")
@RestController
@RequestMapping("/trap")
public class TrapController {
    @Autowired
    private ITrapService service;

    @ApiOperation("新增圈闭信息")
    @PostMapping
    public Response<String> addTrap(@RequestBody TrapAddVM vm){
        service.addTrap(vm);
        return Response.success();
    }

    @ApiOperation("修改圈闭")
    @PutMapping
    public Response<String> updateTrap(@RequestBody TrapUpdateVM vm){
        service.updateTrap(vm);
        return Response.success();
    }

    @ApiOperation("删除圈闭")
    @DeleteMapping("/{trapId}")
    public Response<String> deleteById(@PathVariable String trapId){
        service.deleteById(trapId);
        return Response.success();
    }

    @ApiOperation("查询圈闭总数")
    @GetMapping("/count")
    public Response<Integer> count(){
        return Response.success(service.count());
    }

    @ApiOperation("分页多条件查询圈闭")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zoneId",value = "区带编号"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class)
    })
    @GetMapping("/page")
    public Response<Page<TrapVM>> findByPage(Integer pageNum,Integer pageSize,String zoneId){
        Page<TrapVM> page = service.findByPage(pageNum, pageSize, zoneId);
        return Response.success(page);
    }

    @ApiOperation("查询所有圈闭类型")
    @GetMapping("/type")
    public Response<List<TrapTypeVM>> findAllType(){
        List<TrapTypeVM> list = service.findAllType();
        return Response.success(list);
    }
}
